package com.xiaobai.zhuangxiuguanjia.model;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Android Studio
 * Project: ZhuangXiuGuanJia
 * Author: Jack
 * Email: jackfangqi1314@gmail.com/jackfangqi@163.com
 * Date: 2015/6/17
 */
public class RecommendAppInfo {
    private String version;
    private String action;
    private int errorCode;
    private int allRows;
    private List<AppData> appDataList;

    public String getAction() {
        return action;
    }

    public int getAllRows() {
        return allRows;
    }

    public List<AppData> getAppDataList() {
        return appDataList;
    }

    public int getErrorCode() {
        return errorCode;
    }

    public String getVersion() {
        return version;
    }

    public void parseJson(JSONObject jsonObject) {
        if (jsonObject != null) {
            try {
                version = jsonObject.getString("version");
                action = jsonObject.getString("action");
                errorCode = jsonObject.getInt("errorCode");
                allRows = jsonObject.getInt("allRows");

                JSONArray array = jsonObject.getJSONArray("data");
                appDataList = new ArrayList<>();
                int length = array.length();
                for (int i = 0; i < length; i++) {
                    JSONObject object = array.getJSONObject(i);
                    AppData appData = new AppData();
                    appData.parseJson(object);

                    appDataList.add(appData);
                }

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }
}
